package com.xuhuan.demo.pattern.factory.factorymethod.pizzastore.order;

import com.xuhuan.demo.pattern.factory.factorymethod.pizzastore.pizza.Pizza;
import java.util.Scanner;

/**
 * @author huan.xu
 * @date 2021/10/3 21:54
 * @description 订购披萨
 */
public abstract class OrderPizza {

  public abstract Pizza createPizza(String orderType);

  public OrderPizza() {
    do {
      String orderType = getOrderType();
      if ("0".equals(orderType)) {
        System.out.println("退出订购！");
        break;
      }
      Pizza pizza = this.createPizza(orderType);
      if (pizza != null) {
        System.out.println("下单成功！");
        pizza.prepare();
        pizza.bake();
        pizza.cut();
        pizza.box();
      } else {
        System.out.println("没有您选择的披萨种类！");
        break;
      }
    } while (true);
  }

  private String getOrderType() {
    Scanner scanner = new Scanner(System.in);
    System.out.println("请选择要订购的披萨:cheese、pepper，退出订购请输入：0");
    return scanner.next();
  }
}
